<template>
    <div class="body">
    <div class="header">
      <div class="text">购购物卡 享更多优惠</div>
    </div>
    <!-- g购物卡 -->
    <div class="six">
      <ul>
        <li @click="nav({goods_id:7704})">
          <div class="btn">立即购买</div>
        </li>
        <li @click="nav({goods_id:7708})">
          <div class="btn">立即购买</div>
        </li>
        <li @click="nav({goods_id:7711})">
          <div class="btn">立即购买</div>
        </li>
        <li @click="nav({goods_id:7714})">
          <div class="btn">立即购买</div>
        </li>
      </ul>
    </div>
    <!-- 主界面Tag -->
    <div class="one">
      <van-tabs
        v-model="activeName"
        sticky
        animated
        background='#ffffff'
        color='#F70000'
        title-active-color='#F70000'
        title-inactive-color='#000000'
        line-width='60px'
        @click="create"
      >
        <van-tab
          title="食品饮料"
          name="67"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab
          title="个护美妆"
          name="69"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab
          title="家用电器"
          name="70"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab
          title="生活家居"
          name="71"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab
          title="母婴玩具"
          name="72"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab
          title="箱包服饰"
          name="73"
        >
          <div class="item">
            <ul>
              <li
                v-for="item in list"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <div class="back">
                  <img
                    class="one-hit"
                    :src="item.goods_img"
                    alt=""
                  >
                </div>

                <div class="text-one"> {{item.goods_name}}</div>
                <div class="money-Hot">¥ {{item.active_price}}</div>
                <div class="Go-hot">立即抢购</div>
              </li>
            </ul>
          </div>
          <div class="add">
            <ul>
              <li
                v-for="item in lister"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  :src="item.goods_img"
                  class="img"
                  alt=""
                >
                <div class="text">
                  {{item.goods_name}}
                </div>
                <div class="money">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
              </li>
            </ul>
          </div>
        </van-tab>
      </van-tabs>
    </div>
    <div
      class="moy"
      @click="ping"
    >查看更多></div>
    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
      <!-- <i class="iconfont icon-zhiding"></i> -->
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { index, Coupondev } from '@/api/index'
import { share } from '../../js/public'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      list: [],
      lister: [],
      listdev: [],
      show: false,
      system: getSystem(),
      atr: [],
      atrdev: [],
      listerdev: [],
      share: true,
      scrollTop: 0,
      btnFlag: false,
      showTips: false,
      activeName: '67',
    }
  },
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.create(this.activeName)
    // this.weixin()
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
    share({
      title: '媛福达app商城，享受美好生活!',
      desc: '新品来袭低至9.9元起，享受美好生活，不忘初心 筑梦前行！',
      imgUrl: 'https://download.yuanfuda933.com/h5/images/fine.png',
      shareUrl: 'https://download.yuanfuda933.com/h5/other2.html#/fine',
      share: this.share,
    })
  },
  // 组件方法
  methods: {
    ping () {
      window.location.href = 'yfd://yfdmall:8080/homePage'
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    async create (id) {
      try {
        const res = await index({
          id: id
        })
        console.log(res.data.data.types);
        this.list = res.data.data.types[0].goods.slice(0, 2)
        this.lister = res.data.data.types[0].goods.slice(2, 24)

        // var resultdev = []
        // for (var i = 0; i < atrdev.length; i += 3) {
        //   resultdev.push(atrdev.slice(i, i + 3));
        // }
        // this.lister = resultdev
        // var atr = res.data.data.types[1].goods
        // var result = []
        // for (var i = 0; i < atr.length; i += 3) {
        //   result.push(atr.slice(i, i + 3));
        // }
        // this.atr = result
        // // console.log(this.atr);
        // this.listdev = res.data.data.types[2].goods
      } catch (err) {
        console.log('错误');
      }
    },
    // 跳转下载
    nav (item) {
      console.log(item.goods_id);
      // window.locaition.href = 'http://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk?squId=' + 'item.goods._id'
      window.location.href = 'yfd://yfdmall:8080/goodsDetail?spuId=' + item.goods_id
    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  // height: 93.12rem;
  margin: 0 auto;
  line-height: 1.5;
  background: #ff082d;
  font-family: Arial, Helvetica;
  .moy {
    width: 2.746667rem;
    height: 0.613333rem;
    margin: 0.266667rem auto;
    border-radius: 0.4rem;
    font-size: 0.373333rem;
    color: #ff0000;
    text-align: center;
    line-height: 0.61rem;
    border: 0.026667rem solid#FFFFFF;
    background: -webkit-linear-gradient(top, #fcd073, #f6dba4);
  }
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  // 主界面
  .one {
    width: 9.466667rem;
    margin: 0 auto;
    overflow: hidden;
    border-top-left-radius: 0.266667rem;
    border-top-right-radius: 0.266667rem;
    .image {
      margin: 0.233333rem auto;
      width: 9.466667rem;
      height: 1.84rem;
    }
    .item {
      padding-top: 0.266667rem;
      overflow: hidden;
      width: 10rem;
      ul li {
        float: left;
        position: relative;
        width: 4.613333rem;
        margin-left: 0.0953333rem;
        margin-bottom: 0.16rem;
        height: 7.226667rem;
        border-radius: 0.266667rem;
        background-color: #ffffff;
        .back {
          width: 100%;
          height: 4.56rem;
          background-color: #f8f8f7;
          border-radius: 0.266667rem;
          .one-hit {
            width: 4.053333rem;
            height: 3.693333rem;
            margin-top: 0.266667rem;
            margin-left: 0.32rem;
          }
        }
        .text-one {
          width: 4.04rem;
          height: 1.093333rem;
          font-size: 0.373333rem;
          color: #000000;
          margin: 0 auto;
          // font-weight: 600;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .money-Hot {
          width: 1.733333rem;
          height: 0.533333rem;
          font-size: 0.426667rem;
          margin-left: 0.32rem;
          margin-top: 0.08rem;
          font-weight: 600;
          color: red;
        }
        .Go-hot {
          // position: absolute;
          // right: 10%;
          // bottom: 3%;
          width: 4.106667rem;
          height: 0.72rem;
          margin: 0 auto;
          font-size: 0.426667rem;
          text-align: center;
          line-height: 0.72rem;
          color: #ffffff;
          border-radius: 0.1rem;
          // border: 0.013333rem solid #6d240b;
          background: #f80018;
        }
      }
    }
    .add {
      width: 9.466667rem;
      overflow: hidden;
      ul li {
        float: left;
        width: 3.12rem;
        height: 4.473333rem;
        border-radius: 0.166667rem;
        background: #ffffff;
        margin-bottom: 0.133333rem;
        margin-right: 0.03rem;
        .img {
          width: 2.533333rem;
          height: 2.613333rem;
          margin-top: 0.186667rem;
          margin-left: 0.32rem;
        }
        .text {
          margin: -0.206667rem auto 0;
          width: 2.666667rem;
          height: 0.9rem;
          font-size: 0.32rem;
          color: #333333;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .money {
          margin-left: 0.233333rem;
          // width: 1.333333rem;
          height: 0.426667rem;
          font-size: 0.266667rem;
          color: #ff301e;
          span {
            font-size: 0.426667rem;
          }
        }
      }
    }
    .moy {
      width: 2.746667rem;
      height: 0.613333rem;
      margin: 0.266667rem auto;
      border-radius: 0.4rem;
      font-size: 0.373333rem;
      color: #ff0000;
      text-align: center;
      line-height: 0.61rem;
      border: 0.026667rem solid#FFFFFF;
      background: -webkit-linear-gradient(top, #fcd073, #f6dba4);
    }
    .title {
      margin: 0.133333rem auto;
      width: 9.066667rem;
      height: 0.666667rem;
      color: #ffffff;
      text-align: center;
      font-size: 0.48rem;
      letter-spacing: 0.08rem;
    }
  }
  .header {
    background: url("../../assets/img/fine/header.png") no-repeat;
    background-size: contain;
    width: 10rem;
    height: 14.8rem;
    overflow: hidden;
    .text {
      width: 5.6rem;
      height: 0.533333rem;
      font-weight: 600;
      text-align: center;
      font-size: 0.533333rem;
      margin: 13.8rem auto 0;
      color: #fcbe7c;
    }
  }
  // g购物卡
  .six {
    border-radius: 0.266667rem;
    width: 9.6rem;
    margin: 0.266667rem auto;
    height: 3.333333rem;
    background: -webkit-linear-gradient(top, #ff9e57, #ff95a2);
    ul {
      overflow: hidden;
      padding-top: 0.153333rem;
      li {
        margin-left: 0.13rem;
        width: 2.24rem;
        height: 2.96rem;
        float: left;
        .btn {
          width: 1.6rem;
          height: 0.56rem;
          font-size: 0.266667rem;
          color: #ffffff;
          margin: 2.2rem auto 0;
          text-align: center;
          border-radius: 0.233333rem;
          line-height: 0.56rem;
          background: -webkit-linear-gradient(top, #e86277, #ff0026);
          animation: mymove 2s infinite;
          -webkit-animation: mymove 2s infinite; /*Safari and Chrome*/
          animation-direction: alternate; /*轮流反向播放动画。*/
          animation-timing-function: ease-in-out; /*动画的速度曲线*/
          /* Safari 和 Chrome */
          -webkit-animation: mymove 2s infinite;
          -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
        }
      }
      li:nth-child(1) {
        background: url("../../assets/img/fine/110@2x.png") no-repeat;
        background-size: contain;
      }
      li:nth-child(2) {
        background: url("../../assets/img/fine/230@2x.png") no-repeat;
        background-size: contain;
      }
      li:nth-child(3) {
        background: url("../../assets/img/fine/590@2x.png") no-repeat;
        background-size: contain;
      }
      li:nth-child(4) {
        background: url("../../assets/img/fine/1000@2x.png") no-repeat;
        background-size: contain;
      }
    }
  }
  @keyframes mymove {
    0% {
      transform: scale(1); /*开始为原始大小*/
    }
    25% {
      transform: scale(1.1); /*放大1.1倍*/
    }
    50% {
      transform: scale(1);
    }
    75% {
      transform: scale(1.1);
    }
  }
  @-webkit-keyframes mymove /*Safari and Chrome*/ {
    0% {
      transform: scale(1); /*开始为原始大小*/
    }
    25% {
      transform: scale(1.1); /*放大1.1倍*/
    }
    50% {
      transform: scale(1);
    }
    75% {
      transform: scale(1.1);
    }
  }
}
</style>
